/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import static persistencia.DBManagerIngresos.conexion;
import modelo.tabla.Ingresos;
import modelo.MetodosIngresos;

/**
 * Panel en el que Rellenamos campo por campo para poder crear el modelo
 * @author Kevin
 */
public class JPCrearIngreso extends javax.swing.JPanel {

    ArrayList<Ingresos> al;
    //ArrayList<Pacientes> ap;
    /**
     * Creates new form JPModeloCreacion
     */
//        public void actualizarIngresos() throws SQLException, ClassNotFoundException{
//        jComboIdPaciente.removeAllItems();
//        MetodosIngresos mti = new MetodosIngresos();
//        al = mti.getIngresos();
//        for (int i = 0; i < al.size(); i++) {
//            jComboIdPaciente.addItem(al.get(i).getId()); //+al.get(i).getNombre());
//        }
//    }
//        public void actualizarIdPacientes() throws SQLException, ClassNotFoundException{
//        jComboIdPaciente.removeAllItems();
//        MetodosPacientes mti = new MetodosPacientes();
//        ap = mti.getIPacientes();
//        for (int i = 0; i < ap.size(); i++) {
//            jComboIdPaciente.addItem(ap.get(i).getId() +al.get(i).getNombre());
//        }
//    }
        
    public JPCrearIngreso() throws SQLException, ClassNotFoundException {
        initComponents();

        
            jbCrear.addActionListener(new ActionListener() {
                
            @Override
            public void actionPerformed(ActionEvent e) {
                String nFechaI = (String) jtfFechaI.getText();
                Ingresos nFechaIngreso = new Ingresos(nFechaI);
                String nIdPaciente = (String) jComboIdPaciente.getSelectedItem();
                Ingresos nId = new Ingresos(nIdPaciente);
                MetodosIngresos mti = null;
                try {
                    mti = new MetodosIngresos();
                    mti.modIngresos(nFechaIngreso,nId);
                    System.out.println ("Ingreso Modificado");
                    //actualizarIngresos();
                    JOptionPane.showMessageDialog(null, "Ingreso Modificado");
                } catch (SQLException ex) {
                    Logger.getLogger(JPCrearIngreso.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
               
        });
        
    }
   

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jlNombreModelo = new javax.swing.JLabel();
        jtfFechaI = new javax.swing.JTextField();
        jbCrear = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jComboIdPaciente = new javax.swing.JComboBox();

        setLayout(new java.awt.GridBagLayout());

        jlNombreModelo.setText("Fecha de Ingreso:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        add(jlNombreModelo, gridBagConstraints);

        jtfFechaI.setMinimumSize(new java.awt.Dimension(300, 20));
        jtfFechaI.setName(""); // NOI18N
        jtfFechaI.setPreferredSize(new java.awt.Dimension(300, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 15, 5);
        add(jtfFechaI, gridBagConstraints);

        jbCrear.setText("Crear");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 10;
        add(jbCrear, gridBagConstraints);

        jLabel3.setText("IdPaciente:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        add(jLabel3, gridBagConstraints);

        jComboIdPaciente.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboIdPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboIdPacienteActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 15, 5);
        add(jComboIdPaciente, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void jComboIdPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboIdPacienteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboIdPacienteActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox jComboIdPaciente;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JButton jbCrear;
    private javax.swing.JLabel jlNombreModelo;
    private javax.swing.JTextField jtfFechaI;
    // End of variables declaration//GEN-END:variables
}
